﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Collections;
using System.Text;
using System.Web.Mvc;

namespace ChoViet.Lib.Helpers
{
    public static class SortExtension
    {
        public static string Sort(this HtmlHelper htmlHelper, string title, string order, string direction, string selected)
	    {
            direction = direction.ToLower();
            order = order.ToLower();
            selected = selected.ToLower();

            StringBuilder  html = new StringBuilder();
            string[] images = new string[] { "sort_asc.png", "sort_desc.png", "sort_none.png" };
            int index = Convert.ToInt32(direction == "desc");

            index = (order == selected) ? index : 2;
		    direction = (direction == "desc") ? "asc" : "desc";

			html.Append(string.Format("<a href=\"javascript:tableOrdering('{0}','{1}');\" title=\"Click cột này để sắp xếp\" >", order, direction));
            html.Append(title);
            html.Append(string.Format("&nbsp;<img src=\"/Images/{0}\" valign=\"middle\" />", images[index]));

            return html.ToString();
		}
        public static string SortNoImg(this HtmlHelper htmlHelper, string title, string order, string direction, string selected, string css)
        {
            TagBuilder a = new TagBuilder("a");
            a.InnerHtml = title;
            a.AddCssClass(order == selected ? css : string.Empty);
            a.Attributes.Add("href",string.Format("javascript:tableOrdering('{0}','{1}');",order,direction));
            return a.ToString();
        }
    }
}
